import 'package:flutter/material.dart';
import 'package:flutter_food/core/ext/int_extension.dart';
import 'package:flutter_food/ui/pages/filter/filter.dart';

class HomeDrawerView extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
      width: 200.px,
      child: Drawer(
        child: Column(
          children: [
            _buildHeaderView(context),
            _buildBodyItem(context, Icon(Icons.restaurant), '进餐', () {
              // 关闭抽屉
              Navigator.of(context).pop();
            }),
            _buildBodyItem(context, Icon(Icons.settings), '过滤', () {
              Navigator.of(context).pushNamed(FilterScreen.routeName);
            }),
          ],
        ),
      ),
    );
  }

  Widget _buildHeaderView(BuildContext context) {
    return Container(
      width: double.infinity,
      color: Colors.orange,
      height: 120.px,
      margin: EdgeInsets.only(bottom: 20.px),
      alignment: Alignment(0, 0.5),
      child: Text('开始动手', style: Theme.of(context).textTheme.headline6),
    );
  }

  Widget _buildBodyItem(
      BuildContext context, Icon icon, String title, Function handler) {
    return ListTile(
      leading: icon,
      title: Text(
        title,
        style: Theme.of(context).textTheme.headline4,
      ),
      onTap: handler,
    );
  }
}
